/**
 * Created by aesop on 2015/7/2.
 */

var fs = require('fs');

exports.getList = function(){
  var json = fs.readFileSync("./config.json");
  return JSON.parse(json);

}

exports.add = function(item){
  var json = fs.readFileSync("./config.json");
  var obj = JSON.parse(json);
  if(obj[item.name]){
    item.name = item.name+ Math.random;
  }
  obj[item.name] = item;
  fs.writeFileSync("./config.json", JSON.stringify(obj));
}

exports.remove = function(item){
  var json = fs.readFileSync("./config.json");
  var obj = JSON.parse(json);
  if(obj[item.name]){
    delete obj[item.name];
    fs.writeFileSync("./config.json", JSON.stringify(obj));
  }
}